package com.spring.converter;

import lombok.Data;
import org.springframework.core.convert.converter.Converter;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: tgy
 * @Date: 2020-08-03 10:59
 */
@Data
public class StringToDateConverter implements Converter<String, Date> {

    private String dateFormatter;


    @Override
    public Date convert(String s) {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(this.dateFormatter);

        try {

            return simpleDateFormat.parse(s);

        }catch (Exception e){

            e.printStackTrace();
        }

        return null;
    }
}
